package com.jack.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jack.mapper.ReportMapper;
import com.jack.pojo.OperateLog;
import com.jack.result.ClazzOption;
import com.jack.result.JobOption;
import com.jack.result.PageResult;
import com.jack.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapper reportMapper;


    /**
     * 获取员工职位数据
     * @return
     */
    public JobOption getEmpJobData() {

        List<Map<String,Object>> list = reportMapper.getEmpJobData();

        List<Object> jobList = list.stream().map(item -> item.get("job")).toList();
        List<Object> dataList = list.stream().map(item -> item.get("total")).toList();
        return new JobOption(jobList, dataList);
    }

    /**
     * 获取员工性别数据
     * @return
     */
    public List<Map<String, Object>> getEmpGenderData() {
        return reportMapper.getEmpGenderData();
    }


    /**
     * 班级人数统计
     *
     * @return
     */
    public ClazzOption getStuCountOfClazzData() {
        List<Map<String,Object>> list = reportMapper.getStuCountOfClazzData();
        List<Object> clazzList = list.stream().map(item->item.get("clazzName")).toList();
        List<Object> clazzCount = list.stream().map(item->item.get("clazzCount")).toList();

        return new ClazzOption(clazzList, clazzCount);
    }

    /**
     * 学生学历统计
     *
     * @return
     */
    public List<Map<String, Object>> getStuDegreeData() {

        return reportMapper.getStuDegreeData();
    }

    /**
     * 日志查询
     *
     * @param page
     * @param pageSize
     * @return
     */
    public PageResult<OperateLog> getLogs(Integer page, Integer pageSize) {
        // 开启分页器
        PageHelper.startPage(page, pageSize);

        List<OperateLog> logs = reportMapper.getLogs(page, pageSize);

        Page<OperateLog> p = (Page<OperateLog>) logs;
        return new PageResult<>(p.getTotal(), p.getResult());
    }
}
